import { WebSocket } from "ws";

function defineStore() {
  const wsClients = new Map<string, WebSocket>();

  const add = (id: string, ws: WebSocket) => {
    wsClients.set(id, ws);
  };

  const remove = (id: string) => {
    wsClients.delete(id);
  };

  const getClients = () => {
    return Array.from(wsClients.values());
  };

  const get = (id: string) => {
    return wsClients.get(id);
  };

  const size = () => {
    return wsClients.size;
  };

  return {
    add,
    get,
    size,
    remove,
    getClients,
  };
}

export const wsStore = defineStore();
